package wviz.gui.color;

import prefuse.action.assignment.ColorAction;
import prefuse.util.ColorLib;
import prefuse.visual.VisualItem;

/**
 * This class selects the text colour for each node label based on the number
 * of links it has, and also sets the highlight colour to red.
 */
public class TextColorAction extends ColorAction {

    private static final int BLACK_TEXT_LINK_THRESHOLD = 1;

    public TextColorAction(String group) {
        super(group, VisualItem.TEXTCOLOR, ColorLib.gray(255));
        add("_hover", ColorLib.rgb(255, 0, 0));
    }

    public int getColor(VisualItem item) {
        // Currently using 'always white'.
        return ColorLib.rgb(0, 0, 102);
/*
    // Selects either white or black as the text colour, for maximum
    // contrast, depending on the number of links each node has.
    try {
      final int row = item.getRow();
      final VisualTable visTable = (VisualTable) item.getTable();
      final int links = visTable.getInt(row, "links");
      return links>BLACK_TEXT_LINK_THRESHOLD?
             ColorLib.rgb(255, 255, 255):ColorLib.rgb(0, 0, 0);

    } catch (Exception e) { return super.getColor(item); }
*/
    }
}